package cn.xorange.commons.datasource.configuration;//package cn.xorange.commons.data.configuration;
//
//import com.atomikos.icatch.jta.UserTransactionImp;
//import com.atomikos.icatch.jta.UserTransactionManager;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.boot.autoconfigure.AutoConfigureBefore;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.jta.JtaTransactionManager;
//
//import javax.annotation.Resource;
//import javax.transaction.TransactionManager;
//import javax.transaction.UserTransaction;
//
//@Slf4j
//@Configuration
//@ConditionalOnProperty(prefix = "spring.datasource.global.transaction",value = "jta")
//@AutoConfigureBefore({org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration.class})
//public class AtomikosTransactionConfig {
//
//    @Resource
//    DataSourceConfig dataSourceConfig;
//
//    @Bean
//    public UserTransaction userTransaction() throws Throwable {
//        UserTransactionImp userTransactionImp = new UserTransactionImp();
//        userTransactionImp.setTransactionTimeout(10000);
//        log.debug("Initializing [userTransaction]");
//        return userTransactionImp;
//    }
//    @Bean(initMethod = "init", destroyMethod = "close")
//    @ConditionalOnMissingBean({TransactionManager.class})
//    public UserTransactionManager atomikosTransactionManager() {
//        UserTransactionManager userTransactionManager = new UserTransactionManager();
//        userTransactionManager.setForceShutdown(false);
//        log.debug("Initializing [atomikosTransactionManager]");
//        return userTransactionManager;
//    }
//    @Primary
//    @Bean
//    @ConditionalOnMissingBean
//    // 配置事务管理, 使用事务时在方法头部添加@Transactional注解即可
//    public PlatformTransactionManager transactionManager(UserTransaction userTransaction,
//                                                         TransactionManager transactionManager) {
//        log.debug("Initializing [atomikosTransactionManager]");
//        return new JtaTransactionManager(userTransaction, transactionManager);
//    }
//}
